import * as types from '../mutation-types'
import axios from 'axios'


// initial state
const state = {
  banner: [],
  homedata: {},
  shixunList: [],
  videoDetail: {}

}

// getters
const getters = {


  homedata: state => state.homedata,
  banner: state => state.banner,
  shixunList:state => state.shixunList,
  videoDetail: state => state.videoDetail

}

// actions
const actions = {


  getBarnerData({
    commit
  }) {


    //  axios.get('/api/getzixunlist.ashx?keyword=0&pagecount=3&pageindex=1').then((res) => {
    //    console.log(res)
    //  })

    axios.get('/appAds.json').then((res) => {

      if (res.data) {

        var data = res.data

        commit(types.GET_SWIPER_IMGS, {
          data
        })


      }
    })

  },

  getShixunData({commit}) {

       axios.get('/api/getvideolist.ashx?videonav=1&pagecount=3&pageindex=1').then((res) => {

          if (res.data) {

        var data = res.data

        commit(types.GET_SHIXUN_DATA, {
          data
        })


      }



     })

  },
  getPeriodicalDetail({commit}, { id }) {
    let idString = id
    console.log(idString)
    axios.post(`/api/getvideo.ashx?id=${idString}`).then( (res)=> {

       if (res.data) {

        var data = res.data

        commit(types.GET_VIDEO_DATA, {
          data
        })


      }


    })
  }



}

// mutations
const mutations = {

  [types.GET_SWIPER_IMGS](state, {
    data
  }) {

    state.homedata = data;
    state.banner = data.Banner

    // console.log(state.banner)

  },
  [types.GET_SHIXUN_DATA](state, {data}) {


         state.shixunList= data.list;


  },
  [types.GET_VIDEO_DATA] (state, {data}) {

    state.videoDetail = data

  }




}

export default {
  state,
  getters,
  actions,
  mutations
}
